package com.school.graduation.mine.view;

import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;

import com.school.graduation.R;
import com.school.graduation.common.base.BaseActivity;
import com.school.graduation.mine.presenter.MineReleasedPresenter;
import com.school.graduation.mine.presenter.MineReleasedRecyclerAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MineReleasedActivity extends BaseActivity implements MineReleasedInterface {

    @Bind(R.id.mine_released_recycler)
    RecyclerView mMineReleasedRecycler;
    @Bind(R.id.mine_released_toolbar)
    Toolbar mMineReleasedToolbar;
    private MineReleasedPresenter mPresenter;

    @Override
    public int getContentView() {
        return R.layout.activity_mine_released;
    }

    @Override
    public void initData() {
        mPresenter = new MineReleasedPresenter(this, this);
        initRecycler();
        initToolbar();
        mPresenter.loadMineReleasedGoods(getUserId());
    }

    private void initRecycler() {
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mMineReleasedRecycler.setLayoutManager(layoutManager);
    }

    @Override
    public void setAdapter(MineReleasedRecyclerAdapter adapter) {
        mMineReleasedRecycler.setAdapter(adapter);
    }

    private String getUserId() {
        SharedPreferences preferences = getSharedPreferences("user_cache", MODE_PRIVATE);
        String userId = preferences.getString("id", "");
        return userId;
    }

    private void initToolbar(){
        mMineReleasedToolbar.setTitle("我发布的");
        mMineReleasedToolbar.setTitleTextColor(Color.WHITE);
    }
}
